import {defineStore} from "pinia";
import Project from "@/utils/project";

export const useProjectStore = defineStore('projectStore', {
  state: () => {
    return {
      projectList: [] as Project[]
    }
  },
  actions: {
    addProject(project: any) {
      let add = new Project(project.name, project.description)
      this.projectList.push(add);
    },
    getProjectById(id: string) {
      return this.projectList.find((project) => project.id === id);
    },
    deleteProject(id: string) {
      let index = this.projectList.findIndex(e => e.id === id);
      this.projectList.splice(index, 1);
    },
    updateProject(project: any) {
      this.projectList.forEach(e => {
        if (e.id === project.id) {
          e.name = project.name;
          e.description = project.description;
        }
      })
    }
  }
})
